<?php

namespace app\api\controller;

use app\common\model\AppVersion;
use app\common\model\Nav;
use app\common\model\Slide;

class SettingController
{
    public $noNeedLogin = ['appVersion', 'getNavs', 'getSlides'];
    
    public function appVersion()
    {
        $version = request()->get('version', 0);
        $versionInfo = AppVersion::where('version', '>', $version)->where('status', 1)->order('version DESC')->find();
        if (!empty($versionInfo)) {
            return json([
                'versionCode' => $versionInfo['version'],
                'versionName' => $versionInfo['name'],
                'versionInfo' => $versionInfo['content'],
                'updateType' => $versionInfo['type'],
                'downloadUrl' => getImageUrl($versionInfo['file'])
            ]);
        }
    }
    
    
    public function getNavs()
    {
        $type = request()->get('type', 'home');
        $list = Nav::where('type', $type)->order('list_order asc')->select()->toArray();
        return apiSuccess(data: $list);
    }
    
    public function getSlides()
    {
        $type = request()->get('type', 'home');
        $list = Slide::where('type', $type)->order('list_order asc')->select()->toArray();
        return apiSuccess(data: $list);
    }
    
}